
<?php
$dirList = explode ( '/', $_SERVER ['PHP_SELF'] );
$document_root = $_SERVER ["DOCUMENT_ROOT"];
require "$document_root/$dirList[1]/conf/conf.php";

$connMng = new ConnManger ( $db_conf, $mem_conf );
$connStep = $connMng->getConn_step ();



$result = "normal";
$needle = $_GET['needle'];
$step_mem_achieve_list = Step_count_DAO::getListByOrderAchieveAndNeedle($needle,$connStep);
$mode = $_POST["mode"];
if ($mode == "input") {
        $step_mem_achieve_list = Step_count_DAO::getList($connStep);
        foreach ($step_mem_achieve_list as $step_mem_achieve_list_record) {
                $id = $step_mem_achieve_list_record->getId();
                $inputAchieve = $_POST["achieveall$id"];
                $step_mem_achieve_list_record->setAchievementall($inputAchieve);
                Step_count_DAO::update($step_mem_achieve_list_record,$connStep);
        }
        $step_mem_achieve_list = Step_count_DAO::getListByOrderAchieve($connStep);
        $positionALL=1;
        foreach ($step_mem_achieve_list as $step_mem_achieve_list_record) {
                $step_mem_achieve_list_record->setPositionAll($positionALL);
                Step_count_DAO::update($step_mem_achieve_list_record,$connStep);
                $positionALL++;
        }
}
if (count ( $step_mem_achieve_list ) == 0) {
        $result = "notfound";
}

$step_mem_achieve_list = Step_count_DAO::getListByOrderAchieveAndNeedle($needle,$connStep);

?>

<?php
$page_groupId = GROUP_STEP_MNG;
$page_pageId = PAGE_TOTAL_ACHIEVE_REVISE;
require "$document_root/$dirList[1]/mng/view/framepages/moudle_base.php";
?>


<div class="main-content">
        <div class="search-well">
                <form class="form-inline" style="margin-top: 0px;">
                        用户检索 &nbsp;<input class="input-xlarge form-control"
                                          placeholder="用户昵称/备注" id="4sStoreName" type="text"> &nbsp;
                        <button class="btn btn-default" type="button" id="searchButton">
                                <i class="fa fa-search"></i> 查找
                        </button>
                </form>
        </div>
        <div>(积分排行说明：排行名次按照个人所获总积分多少排列；若总积分形同，则按照总步数多少排列。)</div>
        <br>
        <form method="post" action="" onSubmit="javascript:return window.confirm('确认提交吗？')">
                <table class="table" style="word-break:break-all">
                        <thead>
                        <tr>
                                <th width="10%">总积分排名</th>
                                <th width="7%">ID</th>
                                <th width="10%">头像</th>
                                <th width="10%">昵称</th>
                                <th width="10%">备注</th>
                                <th width="10%">总步数</th>
                                <th >总积分</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        foreach($step_mem_achieve_list as $step_mem_record) {
                                $positon = $step_mem_record->getPositionAll();
                                $id = $step_mem_record->getId();
                                $img = $step_mem_record->getImg();
                                $name = $step_mem_record->getName();
                                $markName = $step_mem_record->getMarkName();
                                $stepAll = $step_mem_record->getStepall();
                                $achievall = $step_mem_record->getAchievementall();
                                echo "
                                <tr>
                                <td>第 $positon 名</td>
                                <td>$id</td>
                                <td><img src='$img' width='35' height='35' /></td>
                                <td>$name</td>
                                <td>$markName</td>
                                <td>$stepAll</td>
                                <td><input type='text' name='achieveall$id' value='$achievall'/></td>
                                </tr>
                                ";
                        }
                        ?>
                        </tbody>
                </table>
                <input type="submit" class='btn btn-danger' value='提交'>
                <input type="hidden" name="mode" id="mode" value="input">
        </form>
        <?php
        require "$document_root/$dirList[1]/mng/view/framepages/footer.php";
        ?>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript">

        needle = "<?php echo $needle?>";
        $('#searchButton').click(function(){
                needle = $('#4sStoreName').val();
                window.location.href = "?needle="+needle;
        });
</script>

<script>

        function init() {
                var msg = "<?php echo $result ?>";
                if (msg == 'notfound') {
                        alert("未检测到相关用户");
                }
        }

</script>


